import Vue from 'vue'
import VueRouter from 'vue-router'
import {Message} from "element-ui";
import Home from '../views/Home'
import Joinus from "../views/Joinus";
import Welcome from "../views/Welcome";
import Register from "../components/Register";
import Gamelist from "../components/Gamelist";
import Upload from "../components/Upload";
import Test from "../components/Test";
import New_register from "../views/New_register";
import zfb from "../views/zfb";
import VueLife from "../components/VueLife";
import ReleaseMain from "../components/ReleaseGame/ReleaseMain";

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    redirect: '/Home'
  },
  {
    path: '/Home',
    component: () => import('../views/Home')
  },
  {
    path: '/Joinus',
    name: 'Joinus',
    component: Joinus
  },
  {
    path: '/Upload',
    name: 'Upload',
    component: Upload
  },
  {
    path: '/Test',
    name: 'Test',
    component: Test
  },
  {
    path:'/VueLife',
    name:'VueLife',
    component: VueLife
  },
  {
    path: '/Welcome',
    name: 'Welcome',
    component: Welcome,
    children:[
      {
        path: '/Welcome/Register',
        name: 'Register',
        component: Register
      },
      {
        path: '/Welcome/Gamelist',
        name: 'Gamelist',
        component: Gamelist
      }
    ]
  },
  {
    path:'/New_register',
    name:'New_register',
    component:New_register
  },
  {
    path:'/zfb',
    name:'zfb',
    component:zfb
  },
  {
    path:'/ReleaseMain',
    name:'ReleaseMain',
    component:ReleaseMain,
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 不需要登录的路径【白名单】
let notNeedLogin = ['/Home','/New_register'];

// 每次路由跳转之前执行
/*router.beforeEach(((to, from, next) => {
  // 如果to.path（要访问的路径），不在白名单里
  if (notNeedLogin.indexOf(to.path) === -1) {
      // 判断TOKEN是否为空
      if (localStorage.getItem('TOKEN') == null) {
          Message.warning('请先登录！');
          // 拦截并跳转到指定页面
          next('/Home');
      }
  }
  // 放行
  next();
}))*/

export default router
